package ute.mvc.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

import ute.mvc.util.DateTimeSerializer;
import ute.mvc.util.TimeSerializer;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@Entity
public class TestAndQuizz implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2424808118626336057L;

	@Id
	@Column(length = 20)
	private String testAndQuizzID;

	@NotEmpty
	@Column(length = 100, nullable = false)
	private String testAndQuizzName;

	@Min(1)
	private int submitTimeAllow;

	@NotNull
	@JsonSerialize(using = DateTimeSerializer.class)
	@DateTimeFormat(pattern = "dd/MM/yyyy hh:mm:ss")
	private Date startDay;

	@NotNull
	@JsonSerialize(using = DateTimeSerializer.class)
	@DateTimeFormat(pattern = "dd/MM/yyyy hh:mm:ss")
	private Date endDay;

	@NotNull
	@Min(1)
	private int testDuration;

	@JsonIgnore
	@OneToMany(mappedBy = "testAndQuizz")
	private Collection<TestPart> listTestPart = new ArrayList<TestPart>();

	@JsonIgnore
	@ManyToOne
	@JoinColumn(name = "openCourse_SubjectId", nullable = false)
	private OpenCourse_Subject openCourse_Subject;

	@JsonIgnore
	@ManyToOne
	@JoinColumn(name = "lecturerId", nullable = false)
	private User lecturer;

	@ManyToMany
	@JsonIgnore
	@JoinTable(name = "TestAndQuizz_Class", joinColumns = @JoinColumn(name = "testAndQuizzId"), inverseJoinColumns = @JoinColumn(name = "classId"))
	private Collection<MyClass> listClass = new ArrayList<MyClass>();


	public int getTestDuration() {
		return testDuration;
	}

	public void setTestDuration(int testDuration) {
		this.testDuration = testDuration;
	}

	public Collection<MyClass> getListClass() {
		return listClass;
	}

	public void setListClass(Collection<MyClass> listClass) {
		this.listClass = listClass;
	}

	public OpenCourse_Subject getOpenCourse_Subject() {
		return openCourse_Subject;
	}

	public void setOpenCourse_Subject(OpenCourse_Subject openCourse_Subject) {
		this.openCourse_Subject = openCourse_Subject;
	}

	public String getTestAndQuizzID() {
		return testAndQuizzID;
	}

	public void setTestAndQuizzID(String testAndQuizzID) {
		this.testAndQuizzID = testAndQuizzID;
	}

	public String getTestAndQuizzName() {
		return testAndQuizzName;
	}

	public void setTestAndQuizzName(String testAndQuizzName) {
		this.testAndQuizzName = testAndQuizzName;
	}

	public int getSubmitTimeAllow() {
		return submitTimeAllow;
	}

	public void setSubmitTimeAllow(int submitTimeAllow) {
		this.submitTimeAllow = submitTimeAllow;
	}

	public Date getStartDay() {
		return startDay;
	}

	public void setStartDay(Date startDay) {
		this.startDay = startDay;
	}

	public Date getEndDay() {
		return endDay;
	}

	public Collection<TestPart> getListTestPart() {
		return listTestPart;
	}

	public void setListTestPart(Collection<TestPart> listTestPart) {
		this.listTestPart = listTestPart;
	}

	public User getLecturer() {
		return lecturer;
	}

	public void setLecturer(User lecturer) {
		this.lecturer = lecturer;
	}

	public void setEndDay(Date endDay) {
		this.endDay = endDay;
	}

}
